#pragma once


#include <opencv2/opencv.hpp> 
using namespace cv;


/// <summary>
/// 视频捕捉
/// </summary>
/// <param name="image"></param>
void video_demo(Mat& image)
{
	VideoCapture capture(0);
	Mat frame;
	while (true)
	{
		capture.read(frame);
		//若无视频讯号则退出
		if (frame.empty()) { break; }
		imshow("frame", frame);

		//TODO:dosomthing
		int c = waitKey(10);
		if (c == 27) { break; }
	}
}

/// <summary>
/// opencv 理论视频稳定处理为2G以下  若文件超过容量 另外起文件处理
/// </summary>
/// <param name="image"></param>
void videosave_demo(Mat& image)
{
	VideoCapture capture(0);
	int frame_height = capture.get(CAP_PROP_FRAME_HEIGHT);	//高
	int frame_width = capture.get(CAP_PROP_FRAME_WIDTH);	//宽
	int frame_count = capture.get(CAP_PROP_FRAME_COUNT);	//总的帧数
	double fps = capture.get(CAP_PROP_FPS);					//每秒帧数
	int fourcc = capture.get(CAP_PROP_FOURCC);				//CAP_PROP_FOURCC 原始视频的编码格式
	std::cout << "frame_height" << frame_height << std::endl;
	std::cout << "frame_width" << frame_width << std::endl;
	std::cout << "frame_count" << frame_count << std::endl;
	std::cout << "fps" << fps << std::endl;

	//保存视频
	VideoWriter vwrite("D:\test.mp4", fourcc, fps, Size(frame_width, frame_height), true);

	Mat frame;
	while (true)
	{
		capture.read(frame);
		//若无视频讯号则退出
		if (frame.empty()) { break; }
		imshow("frame", frame);

		//TODO:dosomthing
		int c = waitKey(10);
		if (c == 27) { break; }
	}

	capture.release();
	vwrite.release();
}

